
<script type="text/javascript" >
var sys_turningimagsId=0;
var defaultImg = global_param.context_name + "/systemfiles/turningimags/defaultTurningImg.png";
var flagForUpdate=2;
$(function() {
	$('#create_timestamp1').daterangepicker(globalUtil.initinfo);
	$('#create_timestamp1').val("");
	$("#list_date").bootstrapTable({
		striped: true, 
	    url: global_param.context_name+'/system/searchturningimags.do',
	    sidePagination : 'server',
	    cache: false,
	    pagination:true,
	    clickToSelect: true,
	    pageNumber:1,                       //初始化加载第一页，默认第一页
        pageSize: 10,                       //每页的记录行数（*）
        pageList: [10, 25, 50, 100],
	    queryParams: queryParams,
        formatNoMatches: function () {  //没有匹配的结果  
            return '无符合条件的记录';  
        },
        formatLoadingMessage: function(){
            return "请稍等，正在加载中。。。";
        },
	    columns: [
    	{
            field: '',
            title: '序号',
            switchable:false,
        	align:"center",
        	valign:"middle",
            formatter: function (value, row, index) {
                    return index+1;
            }
        },
	    {
        	field : 'turningimags_title',
            title : '标题',
	    	align:"center",
	    	valign:"middle"
	    },
	    {
            field : 'creat_user_name',
            title : '创建人',
	    	align:"center",
	    	valign:"middle",
	    	formatter: function (value, row, index) {
	    		return value+row.creat_user_code;
	    	}
        },
	    {
            field : 'create_timestamp',
            title : '创建时间',
	    	align:"center",
	    	valign:"middle"
        },
	    {
        	field : 'enable_flag',
            title : '启用状态',
	    	align:"center",
	    	valign:"middle",
	    	formatter: function (value, row, index) { 
	    		if(value==1){
	    			return "启用";
	    		}else if (value==0){
	    			return "禁用"
	    		}else{
	    			return null;
	    		}
            }
	    },
	    {
        	field : 'sort_order',
            title : '排序',
	    	align:"center",
	    	valign:"middle",
	    	sortable : true
	    }
	    ,
	    {
        	field : 'turningimags_path',
            title : '图片',
	    	align:"center",
	    	valign:"middle",
	    	formatter: function (value, row, index) { 
                return  '<a href="javascript:previewImgFun('+row.id+');" class="iconbtn btn-blue tooltip-test" data-toggle="tooltip" title="预览"><i class="zxfont icon-search"></i></a>';
            }
	    },
	    {
        	field : 'user_name',
            title : '操作',
	    	align:"center",
	    	valign:"middle",
	        switchable:false,
	        clickToSelect:false,
	        searchable:false,
	        formatter:function(value, row, index)
	        {
	        	var html = "";
	        	html += '<a href="javascript:seeImg('+row.id+');" class="iconbtn btn-blue tooltip-test" data-toggle="tooltip" title="查看"><i class="zxfont icon-search"></i></a>';
	        	html += '<a href="javascript:updateImg('+row.id+');" class="iconbtn btn-blue tooltip-test" data-toggle="tooltip" title="编辑"><i class="zxfont icon-edit"></i></a>';
	        	html += '<a href="javascript:deleteImg('+row.id+');" class="iconbtn btn-red tooltip-test" data-toggle="tooltip" title="删除"><i class="zxfont icon-trash"></i></a>';
	        	return html;
	        }
	    }
        ]
	});	   
    //回车查询
    
    $(window).keydown(function(event){
    	if (event.keyCode == 13) {
    		FindData();
        }
    });
});



function queryParams(param) {
    var param = {
    	creat_user : $("#creat_user1").val(),
    	enable_flag : $("#enable_flag1").val(),
    	date_start: $('#create_timestamp1').val().split(' - ')[0],
    	date_end: $('#create_timestamp1').val().split(' - ')[1],
    	sortname:this.sortName,
        sortorder:this.sortOrder,
        pageindex : this.pageNumber,
        pageSize : this.pageSize
    }
    return param;
}


	//查询列表
function FindData() {
	$("#list_date").bootstrapTable("refresh",{pageNumber: 1,pageSize: 10});
}

function clearName(){
	$("#creat_user1").val("");
	$("#create_timestamp1").val("");
	$("#enable_flag1").val("");
}

function previewImgFun(id){
	sys_turningimagsId=id;
	    BootstrapDialog.show({
	    	title: '图片信息',
	    	titleClass: 'text-center',
            size: BootstrapDialog.SIZE_MIDDLE,
	        message: $('<div style="min-height: 350px;"></div>').load('static/html/systemManage/previewTurningimags.html'),
	        buttons: [{
	            label: '关闭',
	            action: function(dialog) {
	                dialog.close();
	            }
	        }]
	    });
}

function updateImg(id){
	sys_turningimagsId=id;
	BootstrapDialog.show({
    	title: '图片信息',
    	titleClass: 'text-center',
        size: BootstrapDialog.SIZE_WIDE,
        message: $('<div style="min-height: 350px;"></div>').load('static/html/systemManage/addTurningimags.html'),
        buttons: [{
            label: '保存',
            cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
            action: function(dialog) {
        		if($(dialog.$modalBody).find('#turningimags_title2').val() == ''){
        			globalUtil.showSuccessMessage('请填写标题!');
        		}else if($(dialog.$modalBody).find('#sys_img_path').val() == ''){
        			globalUtil.showSuccessMessage('请上传图片!');
        		}else{
        			flagForUpdate=1;
            		add_perm(dialog,1);
        		}
            }
        },{
            label: '关闭',
            cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
            action: function(dialog) {
            	deleteForClose();
                dialog.close();
            }
        }]
    });
}

	function seeImg(id){
		sys_turningimagsId=id;
		BootstrapDialog.show({
	    	title: '图片信息',
	    	titleClass: 'text-center',
	        size: BootstrapDialog.SIZE_WIDE,
	        message: $('<div style="min-height: 350px;"></div>').load('static/html/systemManage/seeTurningimags.html'),
	        buttons: [{
	            label: '关闭',
	            cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	            action: function(dialog) {
	                dialog.close();
	            }
	        }]
	    });
	}
		
function addSys_turningimags(){
	sys_turningimagsId=0;
	    BootstrapDialog.show({
	    	title: '图片信息',
	    	titleClass: 'text-center',
            size: BootstrapDialog.SIZE_WIDE,
	        message: $('<div style="min-height: 350px;"></div>').load('static/html/systemManage/addTurningimags.html'),
	        buttons: [{
	            label: '保存',
	            cssClass:'btn btn-primary col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	            action: function(dialog) {
	        		if($(dialog.$modalBody).find('#turningimags_title2').val() == ''){
	        			globalUtil.showSuccessMessage('请填写标题!');
	        		}else if($(dialog.$modalBody).find('#sys_img_path').val() == ''){
	        			globalUtil.showSuccessMessage('请上传图片!');
	        		}else{
	        			flagForUpdate=0;
	            		add_perm(dialog,0);
	        		}
	            }
	        }, {
	            label: '关闭',
	            cssClass:'btn btn-default col-sm-1 col-sm-offset-4 col-xs-4 col-xs-offset-3',
	            action: function(dialog) {
	            	flagForUpdate=0;
	            	deleteForClose();
	                dialog.close();
	            }
	        }]
	    });
}


function deleteImg(id){
	sys_turningimagsId=id;
	globalUtil.showConfirmMessage('确定删除所选图片？',function(){
		$.ajax({
			url : global_param.context_name + '/system/deleteTurningimags.do', 
			type : 'post',
			async: false,
			data : {
				id:sys_turningimagsId
			},
			cache : false,
			success: function(data){    
			if(data=='success'){
				toastr.success("操作成功");
				$("#list_date").bootstrapTable("refresh",{});
			}
	    }  
	  });
	});
}

	
	function add_perm(dialog,flagForUpdate){
		//查询启用状态轮播图最多为五张
		let countFlag=0;
		if($("#enable_flag2").val()=="1"){
			$.ajax({
		    	async: false,
		    	url : global_param.context_name + '/system/getAllTurningimagsCount.do', 
				type : 'post', 
				data : {
					id:sys_turningimagsId
				},
				success: function(data){
					if(parseInt(data)>4){
						countFlag=1;
						globalUtil.showSuccessMessage('启用图片已超过限制,请重新设置');
					}
				}  
		  	});
			
		}
		
		if(countFlag==1){
			return;
		}
		//保存
		$.ajax({
	    	async: false,
	    	url : global_param.context_name + '/system/saveturningimags.do', 
			type : 'post', 
			data : {
				"id" : $('#turningimags_id').val(),
				"turningimags_title":$('#turningimags_title2').val(),
				"enable_flag":$('#enable_flag2').val(),
				"sort_order":$('#sort_order2').val(),
				"turningimags_path":$('#sys_img_path').val()
				},
			success: function(data){	
					if(data=="success"){
						if(flagForUpdate==0){
							//删除旧图片
		            		if(firstImg!=$('#sys_img_path').val()){
			            		 $.ajax({
			                        type: "POST",
			                        url: global_param.context_name + "/personnelManage/deleteImg.do",
			                        data:{
			                            "oldFileName": $('#head_img_path').val(),
			                            "firstImg":firstImg,
			                            "defaultImg":defaultImg,
			                            "flag":"1"
			                        },
			                        async: false,
			                        success: function(json) {
			                            flag = json.result;                                 
			                        }
			                    });  
			            	  }
						}
						dialog.close();
						toastr.success("操作成功!");
						$("#list_date").bootstrapTable("refresh",{});
					}
			}  
	  	});
	
}
</script>

<section class="content-header">
	<h1 class="page-name">轮播图片</h1>
	<ol class="breadcrumb">
	</ol>
</section>
<!-- Main content -->
<section class="content item">
	 <div class="container-fluid">
		<div class="row">
			<div class="box">
        		<div class="box-body">
		        	<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
		              <div class="form-group">
		              	<label for="user_name1">创建人</label>
		                <input type="text" class="form-control"  id="creat_user1" style="width: 100%;" placeholder="请输入操作人" >
		              </div>
		            </div>
		            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
		              <div class="form-group">
		                  <label for="create_timestamp1">操作日期</label>
						  <input type="text" class="form-control"  id="create_timestamp1" style="width: 100%;" placeholder="请选择日期">
		              </div>
		            </div>	
		            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
		            	<div class="form-group">
			                <label for="enable_flag1">启用状态</label>
			                <select class='form-control' id='enable_flag1' name='enable_flag1'>
				                <option value='' selected='true'>请选择 </option>
				                <option value='1'>启用</option>
				                <option value='0'>禁用 </option>
			                </select>
		                </div>
		            </div>
		            <div class="col-lg-3 col-md-3 col-sm-5 col-xs-12">
		            	<div class="form-group">
		             	   <label>&nbsp;</label>
		             	   <div class="row">
							   <div class="col-xs-6">
								   <button type="button" class="btn btn-block btn-primary" onclick="FindData()">查询</button>
							   </div>
							   <div class="col-xs-6">
								   <button type="button" class="btn btn-block btn-default" onclick="clearName()">清空</button>
							   </div>
						   </div>
					    </div>
		            </div>
		    	</div>
		   </div>
		</div>
    </div>
    
	<div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
              <div class="box-header">
                 <h3 class="box-title">数据列表</h3>
              </div>
              <div class="box-body">
              		<div class="btn-group" id="toolZoom">
					    <button type="button" class="btn btn-toolgroup" onclick="addSys_turningimags();"><i class="fa fa-plus"></i>新增</button>
					</div>
				<table id="list_date" data-toolbar="#toolZoom">
				</table>
			  </div>
            </div>
         </div>
     </div>
</section>
